from django.db import models
from apps.api.models import ApiCase


class Job(models.Model):
	url = models.URLField(verbose_name='接口地址')
	params = models.CharField(max_length=1000, verbose_name='用例参数', default=None)
	case = models.ForeignKey(ApiCase, on_delete=models.DO_NOTHING, verbose_name="用例ID")
	trigger = models.CharField(max_length=10, verbose_name='触发器')
	job_cron = models.CharField(max_length=30)
	task_id = models.CharField(max_length=50, verbose_name='调度ID')
	job_status = models.SmallIntegerField(default=1, verbose_name='任务状态')
	create_time = models.DateTimeField(auto_now_add=True)
	update_time = models.DateTimeField(auto_now=True)
	deleted = models.BooleanField(default=False)

	class Meta:
		db_table = 'tiresias_job'
		verbose_name = '任务表'
		verbose_name_plural = verbose_name


class JobReport(models.Model):
	case_id = models.IntegerField(verbose_name='用例ID')
	task_id = models.CharField(max_length=50, verbose_name='调度ID')
	expect = models.TextField(verbose_name='预期')
	actual = models.BooleanField(verbose_name='实际结果')
	response_data = models.TextField(verbose_name='响应数据')
	report_time = models.DateTimeField(auto_now_add=True)

	class Meta:
		db_table = 'tiresias_job_report'
		verbose_name = 'job运行结果'
		verbose_name_plural = verbose_name
